From 5bf4891768f1ee359ee5795272c289b40745aed5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 30 Jul 2022 11:13:39 -0700 Subject: get invoice by uuid --- src/routes/invoice/[id].js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/routes/invoice/[id].js (limited to 'src/routes/invoice/[id].js') diff --git a/src/routes/invoice/[id].js b/src/routes/invoice/[id].js new file mode 100644 index 00000000..37ef098d --- /dev/null +++ b/src/routes/invoice/[id].js @@ -0,0 +1,11 @@ +import { get } from '$lib/utils'; + +const username = 'bob', + network = 'lightning'; + +export async function GET({ params }) { + let { id } = params; + let { amount, text } = await get(`/invoice?uuid=${id}`); + + return { body: { amount, text } }; +} -- cgit v1.2.3 From 7168cd2ea39aaa2158412bb5e966e144e8a22733 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 30 Jul 2022 11:50:42 -0700 Subject: invoice updates --- src/routes/[username]/receive.svelte | 2 +- src/routes/invoice/[id].js | 6 +- src/routes/invoice/[id].svelte | 290 +++++++++++++++++------------------ src/routes/invoice/index.js | 4 +- 4 files changed, 144 insertions(+), 158 deletions(-) (limited to 'src/routes/invoice/[id].js') diff --git a/src/routes/[username]/receive.svelte b/src/routes/[username]/receive.svelte index 9ebc0401..e0bf7751 100644 --- a/src/routes/[username]/receive.svelte +++ b/src/routes/[username]/receive.svelte @@ -82,7 +82,7 @@ }; let submit = async () => { - let { id } = await post('/invoice', { amount, username: $page.params.username }); + let { id } = await post('/invoice', { amount, rate: $rate, username: $page.params.username }); console.log(id) goto(`/invoice/${id}`); }; diff --git a/src/routes/invoice/[id].js b/src/routes/invoice/[id].js index 37ef098d..7d18ba86 100644 --- a/src/routes/invoice/[id].js +++ b/src/routes/invoice/[id].js @@ -5,7 +5,9 @@ const username = 'bob', export async function GET({ params }) { let { id } = params; - let { amount, text } = await get(`/invoice?uuid=${id}`); + let huh = await get(`/invoice?uuid=${id}`); + console.log(huh) + let { amount, rate, text } = await get(`/invoice?uuid=${id}`); - return { body: { amount, text } }; + return { body: { amount, rate, text } }; } diff --git a/src/routes/invoice/[id].svelte b/src/routes/invoice/[id].svelte index d1dea907..a9f3cefb 100644 --- a/src/routes/invoice/[id].svelte +++ b/src/routes/invoice/[id].svelte @@ -1,25 +1,25 @@ diff --git a/src/lib/socket.js b/src/lib/socket.js index 14555bd3..36d41ea8 100644 --- a/src/lib/socket.js +++ b/src/lib/socket.js @@ -47,8 +47,8 @@ export function connect() { } export function close() { - if (socket) socket.close(); -} + if (socket) socket.close(); +} function onWebsocketMessage(msg) { let { type, data } = JSON.parse(msg.data); diff --git a/src/lib/utils.js b/src/lib/utils.js index e9d1b73e..22c88522 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -8,7 +8,7 @@ const base = browser ? '' : import.meta.env.VITE_COINOS_URL; export const get = (url) => fetch(base + url, { - headers: { accept: 'application/json'} + headers: { accept: 'application/json' } }).then((r) => r.json()); export const post = (url, body) => diff --git a/src/routes/[username]/index.js b/src/routes/[username]/index.js index 39a216c2..01613574 100644 --- a/src/routes/[username]/index.js +++ b/src/routes/[username]/index.js @@ -1,3 +1,3 @@ export async function GET({ params }) { - return { body: params } + return { body: params }; } diff --git a/src/routes/[username]/index.svelte b/src/routes/[username]/index.svelte index fe1f7754..91744aa3 100644 --- a/src/routes/[username]/index.svelte +++ b/src/routes/[username]/index.svelte @@ -2,8 +2,6 @@ import { AppHeader, Icon } from '$comp'; import { user } from '$lib/store'; export let username; - - console.log($user, username); {#if $user?.username === username} diff --git a/src/routes/[username]/receive.svelte b/src/routes/[username]/receive.svelte index d588eaed..5865d5e5 100644 --- a/src/routes/[username]/receive.svelte +++ b/src/routes/[username]/receive.svelte @@ -94,8 +94,7 @@ }; let submit = async () => { - let { id } = await post('/invoice', { amount, rate: $rate, username: $page.params.username }); - console.log(id) + let { id } = await post('/invoice', { amount, rate: $rate, username: $page.params.username }); goto(`/invoice/${id}`); }; diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index 1e4e2560..85f5a817 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -25,6 +25,6 @@ {#if ready} - + {/if} diff --git a/src/routes/invoice/[id].js b/src/routes/invoice/[id].js index 7d18ba86..9a38604f 100644 --- a/src/routes/invoice/[id].js +++ b/src/routes/invoice/[id].js @@ -6,7 +6,6 @@ const username = 'bob', export async function GET({ params }) { let { id } = params; let huh = await get(`/invoice?uuid=${id}`); - console.log(huh) let { amount, rate, text } = await get(`/invoice?uuid=${id}`); return { body: { amount, rate, text } }; diff --git a/src/routes/invoice/index.js b/src/routes/invoice/index.js index d89f7130..f6b1f2cf 100644 --- a/src/routes/invoice/index.js +++ b/src/routes/invoice/index.js @@ -3,9 +3,12 @@ import { post } from '$lib/utils'; let network = 'lightning'; export async function POST({ request }) { - let { amount, rate, username } = await request.json(); - let { text } = await post('/lightning/invoice', ); - let { uuid: id } = await post('/invoice', { invoice: { amount, currency: 'USD', network, rate, text }, user: { username } }); + let { amount, rate, username } = await request.json(); + let { text } = await post('/lightning/invoice'); + let { uuid: id } = await post('/invoice', { + invoice: { amount, currency: 'USD', network, rate, text }, + user: { username } + }); return { body: { id } }; } diff --git a/src/routes/logout/done.svelte b/src/routes/logout/done.svelte index 894c7b99..50fb766e 100644 --- a/src/routes/logout/done.svelte +++ b/src/routes/logout/done.svelte @@ -1,13 +1,13 @@ diff --git a/src/routes/logout/index.js b/src/routes/logout/index.js index 80e65f8b..6cbae8f2 100644 --- a/src/routes/logout/index.js +++ b/src/routes/logout/index.js @@ -1,26 +1,26 @@ -import cookie from "cookie"; +import cookie from 'cookie'; const opts = { - httpOnly: true, - sameSite: "lax", - path: "/", + httpOnly: true, + sameSite: 'lax', + path: '/' }; export async function GET({ request: { headers } }) { - return { - status: 302, - headers: { - location: "/logout/done", - "set-cookie": [ - cookie.serialize("token", "", { - ...opts, - expires: new Date(0), - }), - cookie.serialize("refresh_token", "", { - ...opts, - expires: new Date(0), - }), - ], - }, - }; + return { + status: 302, + headers: { + location: '/logout/done', + 'set-cookie': [ + cookie.serialize('token', '', { + ...opts, + expires: new Date(0) + }), + cookie.serialize('refresh_token', '', { + ...opts, + expires: new Date(0) + }) + ] + } + }; } -- cgit v1.2.3 From 5428fdf82a4260fa4f5e0bcdb722d6716740d8bf Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 1 Aug 2022 20:50:16 -0700 Subject: update invoice when tip changes --- src/lib/utils.js | 25 +++- src/routes/invoice/[id].js | 9 +- src/routes/invoice/[id].svelte | 282 ++++++++++++++++++++++------------------- src/routes/invoice/index.js | 4 +- 4 files changed, 173 insertions(+), 147 deletions(-) (limited to 'src/routes/invoice/[id].js') diff --git a/src/lib/utils.js b/src/lib/utils.js index 38f2a010..b80a548b 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -9,13 +9,15 @@ const base = browser ? '' : import.meta.env.VITE_COINOS_URL; export const get = (url) => fetch(base + url, { headers: { accept: 'application/json' } - }).then((r) => r.text()).then((body) => { - try { - return JSON.parse(body); - } catch(e) { - throw Error(body); - } - }) + }) + .then((r) => r.text()) + .then((body) => { + try { + return JSON.parse(body); + } catch (e) { + throw Error(body); + } + }); export const post = (url, body) => fetch(base + url, { @@ -27,3 +29,12 @@ export const post = (url, body) => export const copy = (text) => { navigator.clipboard.writeText(text); }; + +export function reverseFormat(val, locale) { + let parts = new Intl.NumberFormat(locale).formatToParts(1111.1); + let group = parts.find((part) => part.type === 'group').value; + let decimal = parts.find((part) => part.type === 'decimal').value; + let reversedVal = val.replace(new RegExp('\\' + group, 'g'), ''); + reversedVal = reversedVal.replace(new RegExp('\\' + decimal, 'g'), '.'); + return Number.isNaN(reversedVal) ? 0 : +reversedVal; +} diff --git a/src/routes/invoice/[id].js b/src/routes/invoice/[id].js index 9a38604f..514e5d69 100644 --- a/src/routes/invoice/[id].js +++ b/src/routes/invoice/[id].js @@ -1,12 +1,9 @@ import { get } from '$lib/utils'; -const username = 'bob', - network = 'lightning'; - export async function GET({ params }) { let { id } = params; - let huh = await get(`/invoice?uuid=${id}`); - let { amount, rate, text } = await get(`/invoice?uuid=${id}`); + let res = await get(`/invoice?uuid=${id}`); + let { amount, rate, text, user: { username }} = await get(`/invoice?uuid=${id}`); - return { body: { amount, rate, text } }; + return { body: { amount, rate, username, text } }; } diff --git a/src/routes/invoice/[id].svelte b/src/routes/invoice/[id].svelte index 1f1a7aa3..0f5a1437 100644 --- a/src/routes/invoice/[id].svelte +++ b/src/routes/invoice/[id].svelte @@ -1,11 +1,16 @@ -{#if $user} -
+
+ {#if $user} + {/if} -
+
+
+
- -
-

Add a tip?

+

Add a tip?

+ +
+ {tipAmountFormatted}{`(${tipAmountSats} SATS)`} + {tipPercent}% +
+ + { + customTipAmount = ''; + tipPercent = e.target.value; + }} + /> -
- {tipAmountFormatted}{`(${tipAmountSats} SATS)`} + {#each tipAmounts as amount} + - {tipPercent}% -
+ {/each} - { - customTipAmount = ''; - tipPercent = e.target.value; - }} - /> - -
- {#each tipAmounts as amount} - - {/each} - -
- $ - handleCustomTipAmount(e)} - class="bg-primary rounded-2xl py-3 px-10 font-semibold mt-2 mr-1 w-full md:w-auto" - placeholder="Other" - /> - -
+ : 'opacity-100' + : !customTipAmount + ? 'opacity-50' + : 'opacity-100'}" + disabled={showMobileTip ? !customTipAmount && !tipAmount : !customTipAmount} + on:click={() => (showMobileTip = false)}>Done
+
+ +